﻿/**
 * This is a part of MCServe, which is available under the Apache license 2.0.
 * With this code, you may do whatever you want as long as that is not in conflict with this license.
 * In addition, you should have a reference to the original project to include (http://mcserve.codeplex.com).
 * 
 * Author       : Lars Krämer ( Xe77a )
 * Website      : http://www.lkraemer.de
 * Project      : MCServe (http://mcserve.codeplex.com)
 * Copyright    : Copyright (c) 2013 lkraemer.de
 * License      : http://mcserve.codeplex.com/license
 * Description  : This part contains general features of the project
 */

using System;
using System.Runtime.InteropServices;

namespace MCServeLib
{
    public class SystemFunctions
    {
        public static String getOsName()
        {
            #region Windows Server
            if (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 2 && Environment.OSVersion.Version.Build == 3790)
                return "Windows Server 2003";
            if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 0 && Environment.OSVersion.Version.Build == 1500)
                return "Windows Home Server";
            #endregion

            #region Windows 8
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 2 && Environment.OSVersion.Version.Build >= 8100 && Environment.OSVersion.Version.Build <= 8249)
                return "Windows 8 Developer Preview";
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 2 && Environment.OSVersion.Version.Build >= 8250 && Environment.OSVersion.Version.Build <= 8399)
                return "Windows 8 Consumer Preview";
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 2 && Environment.OSVersion.Version.Build >= 8400 && Environment.OSVersion.Version.Build <= 9199)
                return "Windows 8 Release Preview";
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 2 && Environment.OSVersion.Version.Build >= 9200)
                return "Windows 8";
            #endregion

            #region Windows 7
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1 && Environment.OSVersion.Version.Build >= 7000 && Environment.OSVersion.Version.Build <= 7099)
                return "Windows 7 Beta";
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1 && Environment.OSVersion.Version.Build >= 7100 && Environment.OSVersion.Version.Build <= 7599)
                return "Windows 7 Release Candidate";
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1 && Environment.OSVersion.Version.Build == 7600)
                return "Windows 7";
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1 && Environment.OSVersion.Version.Build >= 7601 && Environment.OSVersion.Version.Build <= 8099)
                return "Windows 7 Service Pack 1";
            #endregion

            #region Windows Vista
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1 && Environment.OSVersion.Version.Build >= 5600 && Environment.OSVersion.Version.Build <= 5743)
                return "Windows Vista Release Candidate 1";
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1 && Environment.OSVersion.Version.Build >= 5744 && Environment.OSVersion.Version.Build <= 5807)
                return "Windows Vista Release Candidate 2";
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1 && Environment.OSVersion.Version.Build >= 5808 && Environment.OSVersion.Version.Build <= 5999)
                return "Windows Vista Internal Release";
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1 && Environment.OSVersion.Version.Build == 6000)
                return "Windows Vista";
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 0 && Environment.OSVersion.Version.Build == 6001)
                return "Windows Server 2008 / Windows Vista Service Pack 1";
            else if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 0 && Environment.OSVersion.Version.Build == 6002)
                return "Windows Vista Service Pack 2";
            #endregion

            #region Other Windows
            else if (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 2)
                return "Windows XP x64";
            else if (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 1)
                return "Windows XP";
            else if (Environment.OSVersion.Version.Major == 5 && Environment.OSVersion.Version.Minor == 0)
                return "Windows 2000";
            #endregion

            return "Unknown OS (" + Environment.OSVersion.Platform.ToString() + " " + Environment.OSVersion.Version.Major + "." + Environment.OSVersion.Version.Minor + "." + Environment.OSVersion.Version.Build + ")";
        }
        public static String getOsVersion()
        {
            return Environment.OSVersion.Version.Major.ToString() + "." + Environment.OSVersion.Version.Minor.ToString();
        }
        public static String getOsArchitecture()
        {
            return "x" + (Marshal.SizeOf(typeof(IntPtr)) == 8 ? 64 : 86);
        }
    }
}
